MV_CC_RegisterExceptionCallBack

MV_CC_RegisterExceptionCallBack

Register exception message callback.

API Definition

int MV_CC_RegisterExceptionCallBack(
  void           *handle,
  cbException    fExceptionCallBack,
  void           *pUser
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

fExceptionCallBack

[IN] Callback function to receive exception messages, see the details below:

void(__stdcall* cbException)(
  unsigned int    nMsgType,
  void            *pUser
);
nMsgType

[OUT] Exception message type

pUser

[OUT] User data

pUser

[IN] User data

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • Call this API after the device is opened by MV_CC_OpenDevice. When device is exceptionally disconnected, the exception message can be obtained from callback function. For disconnected GigE device, first call MV_CC_CloseDevice to shut down device, and then call MV_CC_OpenDevice to reopen the device.

  • For exception message type macro definition see below:

    Macro Definition

    Value

    Description

    MV_GIGE_EXCEPTION_DEV_DISCONNECT

    0x00008001

    Device disconnected.

  • This API is not supported by CameraLink device.

The following sample code is for reference only.

#include "MvCameraControl.h"

//Exception callback function
void __stdcall ExceptionCB(unsigned int nMsgType, void* pUser)
{
    printf("Exception message is: 0x%x", nMsgType);
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all devices corresponding to specified transport protocol within subnet
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Select the first found online device and create device handle
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Connect device
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;      
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //...other processing

    nRet = MV_CC_RegisterExceptionCallBack(m_handle, ExceptionCB, NULL);

    if (MV_OK != nRet)
    {
        printf("error: RegisterExceptionCallBack fail [%x]\n", nRet);
        return;
    }

    //...other processing

    //Shut device and release resource
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle and release resource
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

MV_CC_RegisterExceptionCallBack

Register exception message callback.

API Definition

int MV_CC_RegisterExceptionCallBack(
  void           *handle,
  cbException    fExceptionCallBack,
  void           *pUser
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

fExceptionCallBack

[IN] Callback function to receive exception messages, see the details below:

void(__stdcall* cbException)(
  unsigned int    nMsgType,
  void            *pUser
);
nMsgType

[OUT] Exception message type

pUser

[OUT] User data

pUser

[IN] User data

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • Call this API after the device is opened by MV_CC_OpenDevice. When device is exceptionally disconnected, the exception message can be obtained from callback function. For disconnected GigE device, first call MV_CC_CloseDevice to shut down device, and then call MV_CC_OpenDevice to reopen the device.

  • For exception message type macro definition see below:

    Macro Definition

    Value

    Description

    MV_GIGE_EXCEPTION_DEV_DISCONNECT

    0x00008001

    Device disconnected.

  • This API is not supported by CameraLink device.

The following sample code is for reference only.

#include "MvCameraControl.h"

//Exception callback function
void __stdcall ExceptionCB(unsigned int nMsgType, void* pUser)
{
    printf("Exception message is: 0x%x", nMsgType);
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all devices corresponding to specified transport protocol within subnet
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Select the first found online device and create device handle
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Connect device
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;      
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //...other processing

    nRet = MV_CC_RegisterExceptionCallBack(m_handle, ExceptionCB, NULL);

    if (MV_OK != nRet)
    {
        printf("error: RegisterExceptionCallBack fail [%x]\n", nRet);
        return;
    }

    //...other processing

    //Shut device and release resource
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle and release resource
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}